package org.example.Service;

import org.springframework.stereotype.Service;

import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;

/**
 * @ClassName GameServerConfigService
 * @Description TODO
 * @Author hongjun
 * @Date 2024/3/24 16:49
 * @Version 1.0
 */
@Service
public class GameServerConfigService {
    private static final String CONFIG_DIR = "/config";
    private static final String CONFIG_FILE = "server.json";

    public String getConfigAsString() {
        String configPath = System.getProperty("user.dir") + CONFIG_DIR + File.separator + CONFIG_FILE;
        System.out.println(configPath);
        try {
            byte[] configBytes = Files.readAllBytes(Paths.get(configPath));
            return new String(configBytes);
        } catch (IOException e) {
            // 处理异常，例如返回错误信息或空字符串
            e.printStackTrace();
            return "{读取异常}"; // 或者返回错误信息
        }
    }
}
